﻿using LogServerApi.Services;
using Microsoft.AspNetCore.Mvc;

namespace LogServerApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LogController : ControllerBase
    {
        [HttpGet(Name = "api.[controller].[action]")]
		public async Task<IActionResult> Download([FromServices] ILogService logService)
		{
            byte[] content = await logService.DownloadExcel();
			return File(content, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "logs.xlsx");
        }

		[HttpPost(Name = "api.[controller].[action]")]
        public IActionResult Push([FromServices] ILogService logService, [FromBody] LogPushRequest log)
        {
            logService.PushLog(log);
            return Ok();
        }
    }
}
